package com.rudolfheszele.smsselector.view;

import com.rudolfheszele.smsselector.R;
import com.rudolfheszele.smsselector.controller.Controller;
import com.rudolfheszele.smsselector.controller.ControllerFactoryFactory;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ContextMenu.ContextMenuInfo;

public class SmsSelectorRulesViewerActivity extends Activity implements View
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.smsselector_rules_viewer_activity_layout);
		mController = ControllerFactoryFactory.getControllerFactory().getController();
        mController.registerView(this);
        if(savedInstanceState != null)
        	mController.restoreState(getId(), savedInstanceState);
	}
	
	@Override
	protected void onResume()
	{
		super.onResume();
		mController.updateView(this);
	}
	
	/**
     * Called just before the activity will be killed.
     * @param outState The variable the state will be saved to
     */
    @Override
    public void onSaveInstanceState(Bundle outState)
    {
    	mController.saveState(getId(), outState);
    }

	@Override
	public int getId()
	{
		return R.layout.smsselector_rules_viewer_activity_layout;
	}
	
	@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	mController.buildMenu(this, menu, null);
    	
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	return mController.menuClicked(this, item);
    }
    
    @Override
    public void onCreateContextMenu(ContextMenu menu, android.view.View view, ContextMenuInfo menuInfo)
    {
    	super.onCreateContextMenu(menu, view, menuInfo);
    	mController.buildMenu(this, menu, view);
    	
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item)
    {
    	return mController.menuClicked(this, item);
    }
	
	private Controller mController;
}
